using System.Collections;
using System.Xml;
using ICSharpCode.TextEditor.Util;

namespace ICSharpCode.TextEditor.Document
{
	public class HighlightRuleSet
	{
		private LookupTable keyWords;

		private ArrayList spans = new ArrayList();

		private LookupTable prevMarkers;

		private LookupTable nextMarkers;

		private char escapeCharacter;

		private bool ignoreCase = false;

		private string name = null;

		private bool[] delimiters = new bool[256];

		private string reference = null;

		internal IHighlightingStrategyUsingRuleSets Highlighter;

		public ArrayList Spans => this.spans;

		public LookupTable KeyWords => this.keyWords;

		public LookupTable PrevMarkers => this.prevMarkers;

		public LookupTable NextMarkers => this.nextMarkers;

		public bool[] Delimiters => this.delimiters;

		public char EscapeCharacter => this.escapeCharacter;

		public bool IgnoreCase => this.ignoreCase;

		public string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				this.name = value;
			}
		}

		public string Reference => this.reference;

		public HighlightRuleSet()
		{
			this.keyWords = new LookupTable(casesensitive: false);
			this.prevMarkers = new LookupTable(casesensitive: false);
			this.nextMarkers = new LookupTable(casesensitive: false);
		}

		public HighlightRuleSet(XmlElement el)
		{
			if (el.Attributes["name"] != null)
			{
				this.Name = el.Attributes["name"]!.InnerText;
			}
			if (el.HasAttribute("escapecharacter"))
			{
				this.escapeCharacter = el.GetAttribute("escapecharacter")[0];
			}
			if (el.Attributes["reference"] != null)
			{
				this.reference = el.Attributes["reference"]!.InnerText;
			}
			if (el.Attributes["ignorecase"] != null)
			{
				this.ignoreCase = bool.Parse(el.Attributes["ignorecase"]!.InnerText);
			}
			for (int i = 0; i < this.Delimiters.Length; i++)
			{
				this.delimiters[i] = false;
			}
			if (el["Delimiters"] != null)
			{
				string innerText = el["Delimiters"]!.InnerText;
				string text = innerText;
				foreach (char c in text)
				{
					this.delimiters[(uint)c] = true;
				}
			}
			this.keyWords = new LookupTable(!this.IgnoreCase);
			this.prevMarkers = new LookupTable(!this.IgnoreCase);
			this.nextMarkers = new LookupTable(!this.IgnoreCase);
			XmlNodeList elementsByTagName = el.GetElementsByTagName("KeyWords");
			foreach (XmlElement item in elementsByTagName)
			{
				HighlightColor value = new HighlightColor(item);
				XmlNodeList elementsByTagName2 = item.GetElementsByTagName("Key");
				foreach (XmlElement item2 in elementsByTagName2)
				{
					this.keyWords[item2.Attributes["word"]!.InnerText] = value;
				}
			}
			elementsByTagName = el.GetElementsByTagName("Span");
			foreach (XmlElement item3 in elementsByTagName)
			{
				this.Spans.Add(new Span(item3));
			}
			elementsByTagName = el.GetElementsByTagName("MarkPrevious");
			foreach (XmlElement item4 in elementsByTagName)
			{
				PrevMarker prevMarker = new PrevMarker(item4);
				this.prevMarkers[prevMarker.What] = prevMarker;
			}
			elementsByTagName = el.GetElementsByTagName("MarkFollowing");
			foreach (XmlElement item5 in elementsByTagName)
			{
				NextMarker nextMarker = new NextMarker(item5);
				this.nextMarkers[nextMarker.What] = nextMarker;
			}
		}

		public void MergeFrom(HighlightRuleSet ruleSet)
		{
			for (int i = 0; i < this.delimiters.Length; i++)
			{
				this.delimiters[i] |= ruleSet.delimiters[i];
			}
			ArrayList c = this.spans;
			this.spans = (ArrayList)ruleSet.spans.Clone();
			this.spans.AddRange(c);
		}
	}
}
